﻿<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="MyShoppingCart.aspx.cs" Inherits="MyShoppingCart" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="Styles/screen.css" rel="stylesheet" type="text/css" media="screen" /> 

</asp:Content>
<asp:Content ID="ShoppingCart" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Label Text="Shopping Cart" Font-Bold="true" Font-Size="XX-Large" ForeColor="Maroon" runat="server" />
    <br />
    <table border="0">
        <tr>
            <td><b>Cart ID: </b></td>
            <td><asp:Label ID="CTIDLabel" runat="server" /></td>
        </tr>
    </table>
    
<asp:Label ID="emptyCartMessage" runat="server" Font-Size="Larger" Text="Your cart is empty." EnableViewState="false" Visible="false" />
<br />
<asp:SqlDataSource ID="sdsDB" 
        ConnectionString="<%$ connectionStrings: AccessConnectionDB %>" 
        ProviderName="<%$ connectionStrings:AccessConnectionDB.ProviderName %>"
        runat="server" />

<asp:AccessDataSource ID="sdsDB2" runat="server" DataFile="~/App_Data/Database1.accdb" OnSelected="Get_Rows"
    SelectCommand="SELECT c.*, p.PD_NAME, p.PD_PRICE 
    FROM CART c INNER JOIN PRODUCT p on c.PD_ID=p.PD_ID
    WHERE CT_ID = @CT_ID"
    UpdateCommand="UPDATE CART SET CT_QTY=@ProductQty WHERE CT_ID= @CT_ID AND PD_ID = @PD_ID"
    DeleteCommand="DELETE FROM CART WHERE CT_ID = @CT_ID AND PD_ID = @PD_ID">
    <SelectParameters>
        <asp:ControlParameter Name="CT_ID" ControlID="CTIDLabel" PropertyName="Text" />
    </SelectParameters>
    <UpdateParameters>
        <asp:ControlParameter Name="CT_ID" ControlID="CTIDLabel" PropertyName="Text" />
    </UpdateParameters>
    <DeleteParameters>
        <asp:ControlParameter Name="CT_ID" ControlID="CTIDLabel" PropertyName="Text" />
    </DeleteParameters>
</asp:AccessDataSource>

<asp:GridView id="ShoppingCartGrid" DataSourceID="sdsDB2" runat="server"
    AutoGenerateColumns="false" DataKeyNames="CT_ID, PD_ID"
    Cellpadding="3"
    ShowFooter="true">
    <Columns>

        <asp:TemplateField HeaderText="ID" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Maroon" 
            ItemStyle-Width="50"
            FooterStyle-ForeColor="White" FooterStyle-BackColor="Maroon">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%#Eval("PD_ID") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Label runat="server" Text='<%#Eval("PD_ID") %>'></asp:Label>
            </EditItemTemplate>
        </asp:TemplateField>
    
        <asp:TemplateField HeaderText="Name" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Maroon" 
            ItemStyle-Width="200"
            FooterStyle-ForeColor="White" FooterStyle-BackColor="Maroon">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%#Eval("PD_NAME") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Label runat="server" Text='<%#Eval("PD_NAME") %>'></asp:Label>
            </EditItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Price" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Maroon" 
        ItemStyle-HorizontalAlign="Right" ItemStyle-Width="60"
        FooterStyle-ForeColor="White" FooterStyle-BackColor="Maroon">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%#String.Format("{0:c}", Eval("PD_PRICE")) %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Label runat="server" Text='<%#String.Format("{0:c}", Eval("PD_PRICE")) %>' />
            </EditItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Qty" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Maroon" 
        ItemStyle-HorizontalAlign="Right" 
        FooterStyle-HorizontalAlign="Right" FooterStyle-ForeColor="White" FooterStyle-BackColor="Maroon">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%#String.Format("{0:D}", Eval("CT_QTY")) %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="ProductQty" runat="server" Text='<%#Bind("CT_QTY") %>' />
            </EditItemTemplate>

            <FooterTemplate>
                <asp:Label Text="Shipping" runat="server" /><br />
                <asp:Label Text="Total" Font-Bold="true" Font-Size="Large" runat="server" />
            </FooterTemplate>
        </asp:TemplateField>
    
        <asp:TemplateField HeaderText="Amount" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Maroon" 
            ItemStyle-HorizontalAlign="Right" 
            FooterStyle-HorizontalAlign="Right" FooterStyle-ForeColor="White" FooterStyle-BackColor="Maroon">
            <ItemTemplate>
                <asp:Label runat="server"
                Text='<%#String.Format("{0:c}", Get_Amount(Eval("PD_PRICE"), Eval("CT_QTY"))) %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Label runat="server"
                Text='<%#String.Format("{0:c}", Get_Amount(Eval("PD_PRICE"), Eval("CT_QTY"))) %>' />
            </EditItemTemplate>
            <FooterTemplate>
                <asp:Label runat="server" Text='<%#String.Format("{0:c}", Get_Shipping()) %>' /><br />
                <asp:Label ID="OrderTotal" runat="server" Font-Bold="true" Font-Size="Large" Text='<%#String.Format("{0:c}", Get_Order_Total()) %>' />
            </FooterTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Edit" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Maroon"
            ItemStyle-HorizontalAlign="Right" 
            FooterStyle-HorizontalAlign="Center" FooterStyle-ForeColor="White" FooterStyle-VerticalAlign="Bottom" FooterStyle-BackColor="Maroon">
            <ItemTemplate>
                <asp:Button Text="Edit" CommandName="Edit" runat="server" />
                <asp:Button Text="Delete" CommandName="Delete" runat="server" />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Button Text="Update" CommandName="Update" runat="server" />
                <asp:Button Text="Cancel" CommandName="Cancel" runat="server" />
            </EditItemTemplate>
            <FooterTemplate>
                <asp:Button Text="Checkout" OnClick="Submit_Form" runat="server" />
            </FooterTemplate>
        </asp:TemplateField>
    </Columns>
        
</asp:GridView>


</asp:Content>
